package GUI;

import java.util.ArrayList;
import java.util.Calendar;

import UserData.Schedule;
import UserData.User_Management;

public class AlarmRunner implements Runnable{

   DigitalClock dc = new DigitalClock("HHmmss");
   String targetTime;
   int curTime;
   int a,b,c;
   int g;
   Schedule sch = new Schedule();
   Calendar cal=Calendar.getInstance();
   ArrayList<Schedule> schList = new ArrayList<Schedule>();
   int index, index1;
   int q,w,e,result;
   public void run() {
      
      sch.setScheduleName("");
      int k ;
      int p;
      int ptemp;
      
   /*   try {
		Thread.sleep(30000);
	} catch (InterruptedException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}*/
         while(true){
           
            
            try {
            	
            
            	q=Integer.parseInt(dc.getText());
            	//System.out.println(q);
            	w=q/10000;
                index=(w-9)%26;
              //  System.out.println(index);
                e=q/100-w*100;
                index1=e/30;
                //System.out.println(index1);
                result=2*index+index1;
                //System.out.println(result);
               
                
			} catch (Exception e) {
				// TODO: handle exception
			}
            p = result;
            k =cal.DATE+3;
            g=0;
            //System.out.println("p"+p+"k"+k);
            //System.out.println(  User_Management.Now_User.Sche_List[1][1].getScheduleName());

            
            
           for(int j = k; j<31; j++){

            for(int i = p; i<26; i++){
            //	System.out.println("p"+i+"k"+j);
            	String aa = User_Management.Now_User.Sche_List[i][j].getScheduleName();
                if(aa!=null){
              //     System.out.println("IMINININNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN");
                   if(!aa.equals(sch.getScheduleName())){
                //	   System.out.println("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD");
                	   sch=User_Management.Now_User.Sche_List[i][j];
                	   g=1;
                	   break;
                   }
                }
                
             }
            if(g==1){
               break;
            }

            
         }
           
      //   System.out.println("sch:"+sch);
        // System.out.println(a+""+b+""+c);
         a=sch.getAlarm();
         b=sch.getStartHour();
         c=sch.getStartMinute();
         
         targetTime =""+(b*10000+c*100-a*1000);
         
         //System.out.println("Target Time:"+targetTime);
         if(dc.getText().equals(targetTime)){
            Alarm al=new Alarm();
            al.setVisible(true);
         }
         try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
         }
                     
   }

}